package main

import (
	"fmt"
	"google.golang.org/protobuf/proto"
	"protoMod/proto/userService"
)

func main() {

	// protobuf 的序列化与反序列化
	u := &userService.Userinfo{
		Username: "tiger",
		Age:      15,
		Hobby:    []string{"c", "t", "rap", "篮球"},
	}
	fmt.Println(u)
	fmt.Println("=========================")
	println(u.GetUsername())
	// 序列化 ==> 转换成二进制数组
	data, _ := proto.Marshal(u)
	fmt.Println(data)
	fmt.Println("=========================")
	// 反序列化
	var u1 userService.Userinfo
	err := proto.Unmarshal(data, &u1)
	fmt.Println(&u1)
	if err != nil {
		return
	}

}
